<template>
    <div class="swiper-container">
        <!-- <div class="tun" style="cursor: -webkit-grab;"> -->
            <div class="gallery-thumbs tun" style="cursor: -webkit-grab;">
                <div class="swiper-wrapper" >
                    <div class="swiper-slide lun" v-for="item in type1">{{item}}</div>
                </div>
            </div>
            <div class="gallery-top">
                <div class="swiper-wrapper">
                    <div class="swiper-slide sun" v-for="(item,key,i) in type2">
                        <!-- <scroll1></scroll1> -->
                        <!-- middle -->
                        <div class="content scroll">
                            <div class="card-list">
                                <div class="card-content">
                                    <div class="df-btn">
                                        <div class="df-btn-row row">
                                            <a href="###" class="col-25 button button-dark df-btn-btn" v-for="it in item">{{it}}</a>
                                        </div>
                                    </div>
                                    <ul class="con">
                                       <li v-for="(obj,i) in productList[key]" v-on:click="look(obj.id)">
                                      
                                          <router-link to="/product"  >
                                            <div to="/product" >
                                                <div class="images">
                                                    <img v-bind:src="obj.img">
                                                </div>
                                                <div class="about">
                                                   {{obj.name}}
                                                </div>
                                                <div class="nums">
                                                   {{obj.units}}
                                                </div>
                                                <div class="price">¥{{obj.price}}</div>
                                            </div>
                                            <div class="car">
                                                <img src="../images/car.png">
                                            </div>
                                           </router-link> 
                            
                                        </li>
                                       
                                    </ul>
                                </div>
                            </div>
                        </div>
                        <!-- middle -->
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import "../../../assets/js/classsj.js";
export default {
    components:{
    },
    data(){
        return{
            type1:["进口水果","国产水果","精选肉类","禽类蛋品","海鲜水产","乳品糕点","新鲜蔬菜","方便速食","粮油杂货","饮料酒水"],
            type2:{
                t1:["全部","奇异果","车厘子","李","莓","牛油果","提子","更多"],
                t2:["全部","苹果","梨","柑桔橙柚","猕猴桃","瓜","葡萄","更多"],
                t3:["全部","进口牛肉","国产牛肉","猪肉","羊肉","香肠","肉制品"],
                t4:["全部","鸡","鸭","鹅/鸽/兔","蛋"],
                t5:["全部","鱼","三文鱼","虾","蟹","贝","活鲜","更多"],
                t6:["全部","奶酪","酸奶/乳酸","牛奶","甜点","月饼"],
                t7:["全部","叶菜类","根茎类","茄果/瓜果","花菜/豆类","菌菇","沙拉菜","更多"],
                t8:["全部","冷冻点心","中式主食","火锅料"],
                t9:["全部","米","杂粮","干货","果干/零食"],
                t10:["全部","果汁/饮料","冲调饮品"]
            },
            productList:{},
            classsj:global.classsj,
        }
    },
    created(){
        var _this=this;
        this.proId=localStorage.getItem("proId");
        $(".cartNone").hide();
        $.ajax({
          type:"get",
          url:"http://localhost:8088/shop2/getClassSj.php",
          data:{type:"classList"},
          dataType:"json",
          success:function(data){
            console.log(data);
            _this.productList=data;
          }
        });
    },
    mounted(){
        var swiperx = new Swiper('.tun', {
            scrollbarHide: false,
            slidesPerView: 5,
            paginationClickable: true,
        });
        var galleryTop = new Swiper('.gallery-top', {
            onSlideChangeStart: function(swiper){  
              for (var i = 0; i < swiperx.slides.length; i++) {
                 swiperx.slides[i].style.color= "black";
                 swiperx.slides[i].style.opacity= 0.7;
              }           
              if (swiper.activeIndex>2) {
                 swiperx.slideTo(swiper.activeIndex-2);
              }
              if(swiper.activeIndex<3){
                swiperx.slideTo(0);
              }
              swiperx.slides[swiper.activeIndex].style.color="green";
            },
        });
        var galleryThumbs = new Swiper('.gallery-thumbs', {
            slidesPerView: 5,
            touchRatio: 0.2,
            onClick: function(swiper){  
              for (var i = 0; i < galleryThumbs.slides.length; i++) {
                galleryThumbs.slides[i].style.color= "black";
                 galleryThumbs.slides[i].style.opacity= 0.7;
              }           
              if (galleryThumbs.slides.index > 2&&galleryThumbs.slides.index<8) {
                 galleryThumbs.slideTo(swiper.clickedIndex-2);
              }
              if(galleryThumbs.slides.index<3){
                galleryThumbs.slideTo(0);
              }
              galleryTop.slideTo(swiper.clickedIndex);
              galleryThumbs.slides[swiper.clickedIndex].style.color="green";
            },
        });
    },
    methods:{
      look:function(id){
          localStorage.setItem("proId",id);
       }
  }
}
    </script>
<style type="text/css">
.tun{
    padding: 0 0.5rem;
}
    .gallery-top {
        margin-top:4.3rem; 
        height: 26.5rem;
        width: 100%;
    }
    .gallery-thumbs,.tun {
        position: absolute;
        top: 2.3rem;
        height: 2rem;
        width: 100%;
        background: #ddd;
    }
    .swiper-wrapper{
        width: 100%;
    }
    .gallery-thumbs .swiper-slide,
    .tun .swiper-slide {
        width: 10%;
        text-align: center;
        font-size: 0.65rem;
        opacity: 0.7;
    }
    .df-lun{
        color: green;
    }
    /*middle*/
     .scroll{
    padding-bottom: 0;
    margin-top: 0rem;
    height: 26.5rem;
    background: white;
   }
   .scroll .df-btn{
    margin-top: 0rem;
    padding-right: 0.5rem;
    border-bottom: 0.01rem solid #ddd;
}
.scroll .df-btn-row{
    margin:0.5rem;
    margin-top: 0;
}
.df-btn-row a{
    text-align: center;
}
   .con li{
    position: relative;
    height: 5.5rem;
    width: 100%;
    border-bottom: 0.01rem solid #ddd;
    background:white;
   }
   .con a{
    display: block;
    width: 100%;
    height: 100%;
   }
   .con .images{
    float: left;
    margin-top: 0.1rem;
    margin-left: 0.5rem;
    width: 4.25rem;
   }
   .con .images:after{
        content:"";
        display:block;
        clear:both;
}
   .con .images img{
    width: 100%;
    height: 4.25rem;
   }
   .con .about{
    color: black;
    margin-left: 7rem;
    font-size:0.8rem; 
   }
   .con .nums{
    position: absolute;
    top: 2.5rem;
    color: grey;
    margin-left: 7rem;
    font-size:0.7rem; 
   }
   .con .price{
    color: red;
    position: absolute;
    top: 4rem;
    margin-left: 7rem;
    font-size:0.7rem; 

   }
   .con .car{
    position: absolute;
    top: 4.5rem;
    right: 0.5rem;
    width: 1.5rem;
    margin-right: 1rem;
    margin-top: -1rem;
   }
   .con .car img{
    width: 100%;
    height: 1.5rem;
   }
   .lun{
    line-height: 2rem;
   }
   .lun:nth-child(1){
    color: green;
   }
   .df-btn-btn{
    margin-top:0.5rem;
   }
</style>
